/**
 * 
 */
package cn.jhz.filesharingsystem.service;

import java.io.IOException;

import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.highlight.InvalidTokenOffsetsException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.jhz.filesharingsystem.dao.IndexDao;
import cn.jhz.filesharingsystem.model.FileArticle;
import cn.jhz.filesharingsystem.model.Pager;
import cn.jhz.filesharingsystem.util.LuceneUtil;

/**
 * @author asus
 *
 */
@Service("searchServer")
public class SearchServerImpl implements SearchServer {

	@Autowired
	private IndexDao indexDao;


	@Override
	public Query getQuery(String keywords) throws ParseException {
		return LuceneUtil.getQueryParser().parse(keywords);
	}

	@Override
	public IndexSearcher getIndexSearcher() throws IOException {
		return LuceneUtil.getSearcher();
	}

	@Override
	public Pager<FileArticle> getSearchPage(Query query, IndexSearcher indexSearcher) throws IOException, InvalidTokenOffsetsException {
		return indexDao.getSearchPage(query, indexSearcher);
	}

}
